import { readUriToTextAndExplode } from "../readFileToText/openTextFile";
import { RenderData } from "../classes/RadarRenderData";
import { AircraftIcaoData } from "../classes/AircraftIcaoData";

export async function loadIcaoAircraftFile(uri: string) {
    const reg = new RegExp('(?<code>[^\\t]*)\\t(?<conf>[^\\t]*)\\t(?<manufacturer>[^\\t]*)\\t(?<name>.*)');
    const lines = await readUriToTextAndExplode(uri);
    for (const line of lines) {
        const match = reg.exec(line);
        if (match != null && match.groups != undefined) {
            const g = match.groups;
            const aircraft = new AircraftIcaoData()
            aircraft.code = g.code;
            aircraft.conf = g.conf;
            aircraft.manufacturer = g.manufacturer;
            aircraft.name = g.name;
            RenderData.aircraftIcaoData.set(aircraft.code, aircraft);
        }
    }
}